<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="org.edu.system.DBConnect" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.time.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.Calendar" %>
<%
	String tc_id = (String)(session.getAttribute("UserName"));
	String sql = "SELECT * FROM teacher WHERE tc_id = '" + tc_id + "'";
	System.out.println(sql);
	
	Connection con = DBConnect.getCon();
	Statement stmt = null;
	ResultSet rs = null;
	stmt = con.createStatement();
	rs = stmt.executeQuery(sql);//执行命令
	if (rs.next())// 如果记录集非空，表明有匹配的用户ID
	{
			//正常进行
	} else {
		// 否则登录失败
		// response.sendRedirect ( "MyJsp.jsp" );
		response.sendRedirect("login_failure.jsp");
	}
%>
<!DOCTYPE html>
<html>
<head>
<link href="./bootstrap/css/bootstrap.min.css" rel="stylesheet">
<meta charset="utf-8">
<title>教师教务管理系统 - 学生考勤</title>
</head>
<body style="width:900px; margin:0 auto;">
<br>
<table class="table table-striped table-bordered" style="text-align:center">
	<tr>
		<th style="text-align:center">课程名</th>
		<th style="text-align:center">星期</th>
		<th style="text-align:center">上课时间</th>
		<th colspan="2" style="text-align:center">签到状态</th>
		<th style="text-align:center">功能</th>
	</tr>
<%
	sql = "select c.course_name,l.week,l.time,l.lesson_id from course c,lesson l,attendance a where l.lesson_id = a.lesson_id and l.week = a.week and c.course_id = l.course_id and l.tc_id = '"+tc_id+"' GROUP BY l.lesson_id";
	stmt = con.createStatement();
	rs = stmt.executeQuery(sql);//执行命令
	Statement stmt1 = null;
	ResultSet rs1 = null;
	while (rs.next())// 如果记录集非空，表明有匹配的用户ID
	{
		String lesson_id = rs.getString("lesson_id");
		String week = rs.getString("week");
		out.print("<tr>");
		out.print("<td>"+rs.getString("course_name")+"</td>");
		out.print("<td>"+rs.getString("week")+"</td>");
		out.print("<td>"+rs.getString("time")+"</td>");
		sql = "select count(stu_id) as no_qiaodan from attendance WHERE lesson_id = '"+rs.getString("lesson_id")+"' and week ='"+rs.getString("week")+"' and status='2'";
		stmt1 = con.createStatement();
		rs1 = stmt1.executeQuery(sql);//执行命令
		if(rs1.next())
			out.print("<td>未签到："+rs1.getString("no_qiaodan")+"</td>");
		sql = "select count(stu_id) as qiaodan from attendance WHERE lesson_id = '"+rs.getString("lesson_id")+"' and week ='"+rs.getString("week")+"' and status='1'";
		stmt1 = con.createStatement();
		rs1 = stmt1.executeQuery(sql);//执行命令
		if(rs1.next())
			out.print("<td>签到："+rs1.getString("qiaodan")+"</td>");
		out.print("<td><button class=\"btn btn-success btn-sm\" onclick=\"javawwscript:location='./kaoqin_info.jsp?lesson_id="+lesson_id+"'\">查看考勤</button></td>");
		out.print("</tr>");
	}
%>
</table>
</body>
</html>